<?php
/*
 *   This file is part of verbum.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 	 Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */

require_once(ROOT_PATH."pages/userspace.php");
require_once(ROOT_PATH."includes/setupProjectList.php");

$scripts = array();
$desktop = array();
$shorts = array();

$c = new credentials;
$lc = $loader->loadListBy($c,$c->listByGroup($CURRENT_USER->groupid));

$defs = simplexml_load_file(ROOT_PATH."configs/desktop.xml");

foreach($defs->item as $def) {
	$_log->debug("DESKTOP: ".$def->name);
	$rs = false;
	if (isset($def->name->attributes()->op) && 
			isset($def->name->attributes()->action)) {
		if (credentials::contains($lc,
				String::toString($def->name->attributes()->action),
				String::toString($def->name->attributes()->op))) {
			$rs = true;					
		}			
	} else if (credentials::contains($lc,String::toString($def->name))) {
		$rs = true;
	}
	
	if ($rs) {
		$_log->debug("FOUND");
		array_push($scripts,String::toString($def->name));
		if (isset($def->menu)) {
			array_push($desktop,String::toString($def->menu));
		}
		if (isset($def->shortcut)) {
			$s = array("id"=>String::toString($def->shortcut->id),
						"icon"=>String::toString($def->shortcut->icon),
						"text"=>String::toString($def->shortcut->text));
			array_push($shorts,$s);
		}
	} else {
		$_log->debug("NOT FOUND");
	}
}

util::loadScript("userspace"); 

?>
<script language="javascript">
MyDesktop = new Ext.app.App({
	getModules : function(){
		return [
<?php
		foreach ($desktop as $d) {
			echo "new MyDesktop.".$d."(),";
		}
?>            
		];
	},
});
</script>
<?php	
	
util::loadScript("desktop");

foreach ($scripts as $s) {
	util::loadScript($s);
}

?>
<div id="x-desktop"> 
    <dl id="x-shortcuts">
<?php
	foreach ($shorts as $s) {
		echo "<dt id=\"".$s['id']."-shortcut\">";
		echo "<a href=\"#\"><img src=\"images/".$s['icon']."\" />";
		echo "<div>".s($s['text'])."</div></a>";
		echo "</dt>";	
	}
?>
    </dl>
</div>

<div id="ux-taskbar">
<div id="ux-taskbar-start"></div>
<div id="ux-taskbuttons-panel"></div>
<div class="x-clear"></div>
</div>